package exp4.test2;

import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.*;

/**
 * Created by 春旺 on 2017/11/23.
 */
public class CrossGraphTest {
    CrossGraph graph = new CrossGraph();
    @Test
    public void addVertex() throws Exception {
        assertEquals(0,graph.size());
        graph.addVertex("a");
        assertEquals(1,graph.size());
    }

    @Test
    public void removeVex() throws Exception {
        assertEquals(0,graph.size());
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        assertEquals(3,graph.size());
        graph.removeVex("a");
        assertEquals(2,graph.size());
    }

    @Test
    public void addEdge() throws Exception {
        assertEquals(0,graph.getEdgeNumber());
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        assertEquals(0,graph.getEdgeNumber());
        graph.addEdge(new EdgeNode("ab",0,1));
        graph.addEdge(new EdgeNode("ac",0,2));
        graph.addEdge(new EdgeNode("bc",1,2));
        assertEquals(3,graph.getEdgeNumber());
    }

    @Test
    public void removeEdge() throws Exception {
        assertEquals(0,graph.getEdgeNumber());
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        assertEquals(0,graph.getEdgeNumber());
        graph.addEdge(new EdgeNode("ab",0,1));
        graph.addEdge(new EdgeNode("ac",0,2));
        graph.addEdge(new EdgeNode("bc",1,2));
        assertEquals(3,graph.getEdgeNumber());
        graph.removeEdge(new EdgeNode("bc",1,2));
        assertEquals(2,graph.getEdgeNumber());
    }

    @Test
    public void size() throws Exception {
        assertEquals(0,graph.size());
        graph.addVertex("a");
        assertEquals(1,graph.size());
    }

    @Test
    public void isEmpty() throws Exception {
        assertEquals(true,graph.isEmpty());
        graph.addVertex("a");
        assertEquals(false,graph.isEmpty());
    }

    @Test
    public void iteratorBFS() throws Exception {
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        graph.addVertex("d");
        graph.addEdge(new EdgeNode("ab",0,1));
        graph.addEdge(new EdgeNode("ac",0,2));
        graph.addEdge(new EdgeNode("bc",1,2));
        graph.addEdge(new EdgeNode("bd",1,3));
        ArrayList list = new ArrayList();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        assertEquals(list,graph.iteratorBFS(0));
    }

    @Test
    public void iteratorBDFS() throws Exception {
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        graph.addVertex("d");
        graph.addEdge(new EdgeNode("ab",0,1));
        graph.addEdge(new EdgeNode("ac",0,2));
        graph.addEdge(new EdgeNode("bd",1,3));
        ArrayList list = new ArrayList();
        list.add("a");
        list.add("b");
        list.add("d");
        list.add("c");
        assertEquals(list,graph.iteratorBDFS(0));

    }

}